<?php
    class WZList_Test_Book extends \WZ_List
    {
        public function init()
        {
            self::$_itemsByPage = 2;
            self::fields();
            self::$_defaultOrderField = 'title';
            self::$_defaultOrder = 'ASC';
            self::$_defaultRender = 'html';
            self::factory($this);
        }
        
        public static function fields()
        {
            self::$_fields = array(
                array(
                    'name' => 'id_book',
                    'label' => ___('Numéro'),
                    'onList' => false,
                    'sortable' => true,
                    'filterable' => true,
                    'content' => 'self',
                    'php' => ''
                ),
                array(
                    'name' => 'id_author',
                    'label' => ___('Auteur'),
                    'onList' => true,
                    'sortable' => true,
                    'filterable' => true,
                    'content' => 'getAuthor',
                    'php' => ''
                ),
                array(
                    'name' => 'title',
                    'label' => ___('Titre'),
                    'onList' => true,
                    'sortable' => true,
                    'filterable' => true,
                    'content' => 'self',
                    'php' => ''
                ),
                array(
                    'name' => 'year',
                    'label' => ___('Année'),
                    'onList' => true,
                    'sortable' => true,
                    'filterable' => true,
                    'content' => 'self',
                    'php' => ''
                )
            );
        }
        
        public static function getAuthor($idAuthor)
        {
            $q = "SELECT firstname, lastname FROM author WHERE id_author = $idAuthor";
            $res = self::$_db->query($q, false);
            return $res['firstname'] . ' ' . $res['lastname'];
        }
    }